<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.2.1.min.js"></script>
    <script src="jquery.query.js"></script>
    <script>
        //得到主贴的ID
        var ObjId = $.query.get("primaryId");
        $(function () {
            $("#primaryId").val(ObjId);
            findPrimary();
        })

        function findPrimary() {
            $.post("/primary/findById","id="+ObjId,function (primaryObj) {
                $("#titleSpan").html(primaryObj.title);
                $("#createDateSpan").html(primaryObj.createDate);
                $("#authTD").html(primaryObj.user.name);
                $("#contentTD").html(primaryObj.content);

                var str = "";
                for(var i=0;i<primaryObj.list.length;i++){
                    var obj = primaryObj.list[i];
                    str += `<tr><td>${obj.user.name}</td><td>${obj.date}</td>
                            <td>${obj.content}</td></tr>`;
                }
                $("#replyData").html(str);
            })
        }

        function addReply() {
            $.post("/user/getInfo",null,function (userObj) {
                if (userObj.length == 0) {
                    alert("请先登录");
                }else {
                    $.post("/reply/add",$("#f1").serialize(),function (info) {
                        if(info == "ok"){
                            findPrimary();
                        }else {
                            alert("请回复内容");
                        }
                    })
                }
            })
        }
    </script>
</head>
<body>
    <table border="1" width="60%">
        <tr><th>发帖人</th><th>主题:<span id="titleSpan"></span> 发帖时间：<span id="createDateSpan"></span></th></tr>
        <tr>
            <td id="authTD"></td><td id="contentTD"></td>
        </tr>
    </table>
    <hr>
    <table border="1" width="50%">
         <thead>
            <tr><th>回帖人</th><th>回帖时间</th><th>回帖内容</th></tr>
         </thead>
        <tbody id="replyData"></tbody>
    </table>

    回帖：
    <form id="f1">
        <input type="hidden" name="primaryId" id="primaryId">
        内容：<textarea name="content"></textarea><br>
        <input type="button" value="回帖" onclick="addReply()">
    </form>
</body>
</html>